package com.example.service;

import com.example.entity.ArticleRecord;
import com.example.mapper.ArticleRecordMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
帖子业务处理
 */
@Service
public class ArticleRecordService {

    @Resource
    private ArticleRecordMapper articleRecordMapper;

    public void add(ArticleRecord articleRecord) {
        articleRecordMapper.insert(articleRecord);
    }

    public void deleteById(Integer id) {
        articleRecordMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(ArticleRecord articleRecord) {
        articleRecordMapper.updateById(articleRecord);
    }

    public ArticleRecord selectById(Integer id) {
        return articleRecordMapper.selectById(id);
    }

    public List<ArticleRecord> selectAll(ArticleRecord articleRecord) {
        return articleRecordMapper.selectAll(articleRecord);
    }

    public PageInfo<ArticleRecord> selectPage(ArticleRecord articleRecord, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ArticleRecord> articleRecordList = articleRecordMapper.selectAll(articleRecord);
        return PageInfo.of(articleRecordList);
    }

    public void deleteAll() {
         articleRecordMapper.deleteAll();
    }
}
